﻿$(function () {
    layui.use('laydate', function () {
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#birthdateid' //指定元素
        });
    });
// 用户信息
    $.ajax({
        type: "post",
        url: "/expertlib/a/sys/user/infoData",
        dataType: "json",
        async: false,
        data: {
            time: new Date().getTime()
        },
        success: function (data) {
            if (data.state == '1') {
                alert("您的资料已经提交了，不允许修改。");
                window.location.href = 'c_baseinfo.html';
            } else {
                $("#hiduserid").val(data.id);
                $("#loginnameid").val(data.loginName);
                $("#oldloginnameid").val(data.loginName);
            }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            //alert(textStatus);
            // window.location.href='/expertlib/login.html';
        }
    });

// 证件类型  开始
    var documenttypeid = $("#documenttypeid");
    $.ajax({
        type: "get",
        url: "data/getValueListByType7.json",
        async: false,
        data: {
            type: 'documenttype'
        },
        dataType: "json",
        success: function (data) {
            if (data.code == 0) {
                documenttypeid.empty();
                var c_selects = data.selects;

                var html = '';
                $.each(c_selects, function (i) {
                    html += '<option value="' + this.name + '">' + this.name + '</option>';
                });
                documenttypeid.append(html);
            } else {
                alert("证件类型为空");
            }
        }
    });
// 证件类型   结束


// 学位
    var highdegreeid = $("#highdegreeid");
    $.ajax({
        type: "get",
        url: "data/getValueListByType3.json",
        async: false,
        data: {
            type: 'highdegree'
        },
        dataType: "json",
        success: function (data) {
            if (data.code == 0) {
                highdegreeid.empty();
                var c_selects = data.selects;

                var html = '';
                $.each(c_selects, function (i) {
                    html += '<option value="' + this.name + '">' + this.name + '</option>';
                });
                highdegreeid.append(html);
            } else {
                alert("学位为空");
            }
        }
    });

// 学历
    var higheducationid = $("#higheducationid");
    $.ajax({
        type: "get",
        url: "data/getValueListByType2.json",
        async: false,
        data: {
            type: 'higheducation'
        },
        dataType: "json",
        success: function (data) {
            if (data.code == 0) {
                higheducationid.empty();
                var c_selects = data.selects;

                var html = '';
                $.each(c_selects, function (i) {
                    html += '<option value="' + this.name + '">' + this.name + '</option>';
                });
                higheducationid.append(html);
            } else {
                alert("学历为空");
            }
        }
    });


// 党派
    var partyid = $("#partyid");
    $.ajax({
        type: "get",
        url: "data/getValueListByType1.json",
        async: false,
        data: {
            type: 'party'
        },
        dataType: "json",
        success: function (data) {
            if (data.code == 0) {
                partyid.empty();
                var c_selects = data.selects;

                var html = '';
                $.each(c_selects, function (i) {
                    html += '<option value="' + this.name + '">' + this.name + '</option>';
                });
                partyid.append(html);
            } else {
                alert("党派为空");
            }
        }
    });

// 单位类型
    var unittypeid = $("#unittypeid");
    $.ajax({
        type: "get",
        url: "data/getValueListByType4.json",
        async: false,
        data: {
            type: 'unittype'
        },
        dataType: "json",
        success: function (data) {
            if (data.code == 0) {
                unittypeid.empty();
                var c_selects = data.selects;

                var html = '';
                $.each(c_selects, function (i) {
                    html += '<option value="' + this.name + '">' + this.name + '</option>';
                });
                unittypeid.append(html);
            } else {
                alert("单位类型为空");
            }
        }
    });


// 职业资格
    var qualificationsid = $("#qualificationsid");
    $.ajax({
        type: "get",
        url: "data/getValueListByType5.json",
        async: false,
        data: {
            type: 'canvqs'
        },
        dataType: "json",
        success: function (data) {
            if (data.code == 0) {
                qualificationsid.empty();
                var c_selects = data.selects;

                var html = '';
                $.each(c_selects, function (i) {
                    html += '<option value="' + this.name + '">' + this.name + '</option>';
                });
                qualificationsid.append(html);
            } else {
                alert("职业资格为空");
            }
        }
    });


// 职称
    var unittitieid = $("#unittitieid");
    $.ajax({
        type: "get",
        url: "data/getValueListByType6.json",
        async: false,
        data: {
            type: 'titlet'
        },
        dataType: "json",
        success: function (data) {
            if (data.code == 0) {
                unittitieid.empty();
                var c_selects = data.selects;

                var html = '';
                $.each(c_selects, function (i) {
                    html += '<option value="' + this.name + '">' + this.name + '</option>';
                });
                unittitieid.append(html);
            } else {
                alert("职称为空");
            }
        }
    });

//省市二级联动
    var province = $('#province');
    var city = $('#city');
//2. 遍历数据并生成省份列表
    $.ajax({
        type: "get",
        url: "data/getProvinceList.json",
        dataType: "json",
        async: false,
        success: function (data) {
            if (data.code == 0) {
                var html = '';
                var p_selects = data.selects;
                $.each(p_selects, function (i) {
                    html += '<option value="' + this.id + '">' + this.name + '</option>';
                });
                province.append(html);
                //3.添加省change事件
                province.change(function () {
                    var id = this.value;
                    if (id != '') {
                        getcityListByPid(id);
                    } else {
                        $("#city").val("");
                    }

                });
            } else {
                //alert(data.message)
            }
        }
    });


//根据ID获取对应的市
    function getcityListByPid(pid) {
        $.ajax({
            type: "get",
            url: "data/getCityByProvinceIdList.json",
            async: false,
            data: {
                provinceId: pid
            },
            dataType: "json",
            success: function (data) {
                if (data.code == 0) {
                    var c_selects = data.selects;
                    //遍历市生成列表
                    var html = '';
                    $.each(c_selects, function (i) {
                        html += '<option value="' + this.id + '">' + this.name + '</option>';
                    });

                    //删除列表中 除了第一个以外的元素

                    city.children(':gt(0)').remove();

                    city.append(html);
                } else {
                    city.children(':gt(0)').remove();
                }
            }
        });
    }

//复选框内容
    var checkarr = [
        {id: 1, name: "基础研究"},
        {id: 2, name: "应用研究"},
        {id: 3, name: "投资金融"},
        {id: 4, name: "海域海岛论证"},
        {id: 5, name: "战略咨询"},
        {id: 6, name: "教育教学"},
        {id: 7, name: "海洋环境评价"},
        {id: 8, name: "海洋环境"},
        {id: 9, name: "海洋论证"}
    ]
    $.each(checkarr, function (index, ele) {
        if ((index + 1) % 3 == 0) {
            $('#gzxzid').append('<label style="width: 28%" for="check' + ele.id + '"><input name="" class="input_right" id="check' + ele.id + '" type="checkbox">' + ele.name + '</label>');
        } else if (index == checkarr.length - 1 && (index + 1) % 3 != 0) {
            $('#gzxzid').append('<label class="input_none"  for="check' + ele.id + '"><input name="" id="check' + ele.id + '" type="checkbox">' + ele.name + '</label>');
        } else {
            $('#gzxzid').append('<label for="check' + ele.id + '"><input name="" id="check' + ele.id + '" type="checkbox">' + ele.name + '</label>');
        }

    })
    $.each(checkarr, function (index, ele) {
        if ((index + 1) % 3 == 0) {
            $('#gzxzid1').append('<label style="width: 28%" for="check1' + ele.id + '"><input name="" class="input_right" id="check1' + ele.id + '" type="checkbox">' + ele.name + '</label>');
        } else if (index == checkarr.length - 1 && (index + 1) % 3 != 0) {
            $('#gzxzid1').append('<label class="input_none"  for="check1' + ele.id + '"><input name="" id="check1' + ele.id + '" type="checkbox">' + ele.name + '</label>');
        } else {
            $('#gzxzid1').append('<label for="check1' + ele.id + '"><input name="" id="check1' + ele.id + '" type="checkbox">' + ele.name + '</label>');
        }

    })


    //提交选中值
    // $('input:checkbox').each(function () {
    //     if ($(this).attr('checked') == true) {
    //         alert($(this).val());
    //     }
    // });
    //回显
    // $('input:checkbox[value=' + CheckBox值 + ']').attr('checked', 'true');


// 专家基本信息
    $.ajax({
        type: "post",
        url: "/expertlib/a/sys/user/getInfoById",
        dataType: "json",
        data: {
            time: new Date().getTime(),
            id: $("#hiduserid").val()
        },
        success: function (data) {
            $("#usernameid").val(data.name);
            $("#birthdateid").val(data.voBirthday);
            $("#nationid").val(data.nation);
            $("#graduationucid").val(data.graduationuc);
            $("#nowmajorid").val(data.nowmajor);
            //$("#higheducationid").text(data.higheducation);
            $("#higheducationid").val(data.higheducation);
            //$("#sexid").text(data.sex);  //
            $(":radio[name='sex'][value='" + data.sex + "']").prop("checked", "checked");

            $("#nationalityid").val(data.nationality);
            //$("#partyid").text(data.party);
            $("#partyid").val(data.party);
            $("#majorid").val(data.major);
            $("#knowmajorid").val(data.knowmajor);
            //$("#highdegreeid").text(data.highdegree);
            $("#highdegreeid").val(data.highdegree);

            if (data.photo == '') {

            } else {
                //$('#photo').html('<img src="data:image/png;base64,' + data.photo + '" alt="" />');
                $('#photo').html('<img src="/userphoto/' + data.photo + '" alt="" />');
                $('#photo').css('border', '1px solid #ccc')
            }
            //$("#img").val(data.photo);  //
            $("#workunitnameid").val(data.workunitname);
            //$("#unittypeid").text(data.unittype);
            // $("#workofficesid").val(data.workoffices)
            $("#unittypeid").val(data.unittype);

            $("#province").val(data.addressprovinceid);  //

            if (data.addressprovinceid != '') {
                getcityListByPid(data.addressprovinceid);
            }
            $("#city").val(data.addresscityid);  //


            $("#addressdetailid").val(data.addressdetail);
            $("#pluralityid").val(data.plurality);
            $("#qualificationsid").val(data.qualifications);
            $("#dutyid").val(data.duty);
            $("#mobileid").val(data.mobile);

            //$("#documenttypeid").text(data.documenttype); //
            $("#documenttypeid").val(data.documenttype);  //

            // $("#banknoid").val(data.bankno);
            // $("#contactsid").val(data.contacts);
            $("#emailid").val(data.email);
            $("#unittitieid").val(data.unittitie);
            $("#phoneid").val(data.phone);

            $("#documentcodeid").val(data.documentcode);
            // $("#openbankid").val(data.openbank);
            // $("#contactsmobileid").val(data.contactsmobile);
            $("#zipcodeid").val(data.zipcode);
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            //alert(textStatus);
            // window.location.href='/expertlib/login.html';
        }
    });


//打印
    $('#mtjprint').click(function () {
        window.open('p_baseinfo.html');
    })

})
